IF OBJECT_ID('ssf.job_delete') IS NOT NULL
	DROP PROCEDURE ssf.job_delete
GO

CREATE PROCEDURE ssf.job_delete
	@job_name NVARCHAR(128)
AS
/*
<object_header>

<object_summary>
	<purpose><![CDATA[
Delete the job if it exists.
	]]></purpose>
</object_summary>

</object_header>
*/

SET NOCOUNT ON

-- ============
/*<code_comment><![CDATA[declare local variables]]></code_comment>*/
DECLARE	@job_id UNIQUEIDENTIFIER
			, @proc_error INT
-- ============

-- ============
/*<code_comment><![CDATA[get job_id]]></code_comment>*/
SET @job_id = ssf.job_get_job_id(@job_name)
-- ============

-- ============
/*<code_comment><![CDATA[delete job]]></code_comment>*/
IF @job_id IS NOT NULL
BEGIN
	EXECUTE @proc_error = msdb.dbo.sp_delete_job
		@job_id = @job_id

	IF @proc_error <> 0
	BEGIN
		RAISERROR('The call to the procedure <msdb.dbo.sp_delete_job> failed.', 16, 1)
		RETURN @proc_error
	END
END
-- ============

RETURN @@ERROR
GO
